// Widgets/User/AppEnter/AppEnter.js
//获取应用实例
const app = getApp();
const assetsAddress = app.globalData.global.assetsIp + '/' + app.globalData.global.assetsName;
import { queryAppInforMation } from '../../../api/brand';
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    servicePhone: {
      type: String,
      value: '',
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    assetsAddress: assetsAddress,
    appList: [
      { label: '账户余额' , icon: `${assetsAddress}/user/zhhyeIcon.png`, path: '/pages/Earnings/Balance/Balance'},
      { label: '常见问题' , icon: `${assetsAddress}/user/chjwtIcon.png`, path: '/pages/Home/CommonProblem/CommonProblem'},
      { label: '意见反馈' , icon: `${assetsAddress}/user/yjfkIcon.png`, path: '/pages/Users/Suggest/Suggest'},
      { label: '用户协议' , icon: `${assetsAddress}/user/yhxyIcon.png`, path: '/pages/Systems/Feedbacks/Feedbacks'},
      { label: '客服电话' , icon: `${assetsAddress}/user/kfdhIcon.png`, path: '/pages/Systems/CompanyIntroduction/CompanyIntroduction'},
      { label: '设置' , icon: `${assetsAddress}/user/setIcon.png`, path: '/pages/Home/Setting/Setting'},
    ], // 应用专区数据
  },

  /**
   * 组件的方法列表
   */
  methods: {
    goNext(e){
      let url = e.target.dataset.name||e.currentTarget.dataset.name;
      let item = e.target.dataset.item||e.currentTarget.dataset.item;
      if(item.label == '客服电话'){
        if(this.properties.servicePhone == ''){
          wx.showToast({
            title: '暂未获取到客服电话配置！',
            icon: 'none',
          })
          return;
        }
        wx.makePhoneCall({
          phoneNumber: this.properties.servicePhone,
        })
      }else if(item.label == '用户协议'){
        queryAppInforMation({infoType: '2',title: item.label,page: 0})
        .then(res => {
          if(res.success){
            if(res.data.content.length > 0){
              var itm = res.data.content[0];
              if(res.data.content[0].imgUrl){
                wx.navigateTo({
                  url: `/pages/Link/LinkImg/LinkImg?url=${encodeURIComponent(itm.imgUrl)}&title=${JSON.stringify(item.label)}`,
                })
              }else if(itm.jumpUrl && itm.jumpUrl.length > 4 && itm.jumpUrl.substring(0,4) == 'http'){
                wx.navigateTo({
                  url: `/pages/Link/Link/Link?url=${encodeURIComponent(itm.jumpUrl)}&title=${JSON.stringify(item.label)}`,
                })
              }else if(res.data.content[0].content){
                wx.navigateTo({
                  url: `/pages/Link/LinkText/LinkText?content=${JSON.stringify(itm.content)}&title=${JSON.stringify(item.label)}`,
                })
              }
            }else{
              wx.showToast({
                title: '敬请期待',
                icon: 'none',
              })
            }
          }else{
            wx.showToast({
              title: res.errMessage,
              icon: 'none',
            })
          }
        })
      }else{
        wx.navigateTo({
          url: url,
        })
      }
    }
  }
})